﻿namespace NPattern.Tests.AbstractFactory
{
    using System;
    using NPattern.AbstractFactory;
    using NUnit.Framework;

    [TestFixture]
    public class AbstractFactoryTests
    {
        [Test]
        public void Build_WhenMakerValid_ReturnInstance()
        {
            // Given
            AbstractFactory factory = new AbstractFactory(typeof(SampleMaker));
            Sample expected = new Sample { Id = Guid.Empty };
            Sample actual;

            // When
            actual = factory.Build<Sample>(SampleMaker.MyEnum.Two);

            // Then
            Assert.AreEqual(expected.Id, actual.Id);
        }

        [Test]
        public void Build_WhenMakerNotValid_ThrowException()
        {
            Assert.Throws<TypeIsNotMakerException>(() => 
            {
                // Given
                AbstractFactory factory = new AbstractFactory(typeof(string));
                Sample expected = new Sample { Id = Guid.Empty };
                Sample actual;

                // When
                actual = factory.Build<Sample>(SampleMaker.MyEnum.Two);

                // Then throws exception
            });
        }
    }
}
